<?php


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class DemoController extends Controller
{
	public function add(Request $request)
	{
		echo "当前URL：".$request->path()."<br>";
		echo "当前URL：".$request->url()."<br>";
		echo "当前请求方法：".$request->method()."<br>";
		echo "获取请求参数name值：".$request->input('name')."<br>";
		echo "获取请求参数name值：".$request->name."<br>";
		echo "获取请求参数name值：".$request->input('name',"没有值")."<br>";
		echo "获取session值：".session("uuname")."<br>";
		//判断是否有name参数
		if ($request->has('name')) {
			//
		}
		//获取所有参数
		$data = $request->all();
		print_r($data);
		return "加载添加表单！";
		
	}
	
	//测试文件上传代码
	public function doUpload(Request $request)
	{
		// echo "<pre>";
		// var_dump($_FILES);
		//使用传统方式输出上传的信息
		//使用自定义文件上传类处理上传
		$upfile = new \App\Org\Upload("ufile");
		//初始化上传信息
		$upfile->path="./uploads/"; //上传存储路径
		$upfile->typeList = array("image/jpeg","image/png","image/gif");
		//设置允许上传类型
		$upfile->maxSize = 0; //允许上传大小
		
		//执行文件上传
		$res = $upfile->doUpload();
		
		//判断输出
		if($res){
			return "上传成功！".$upfile->saveName;
		}else{
			return "上传失败！原因：".$upfile->error;
		}
	}
	
	//响应实例
	public function response()
	{
		// return "ok";
		// 附加cookie信息的响应设置
        // return response("hello", 200)->withCookie("login","xiaowang");
		
		//响应json格式
		$data = [['name'=>"lisi","age"=>"22","sex"=>"男"],['name'=>"王五","age"=>"22","sex"=>"女"]];
		return response()->json($data);
	}
	
	//视图实例
	public function view()
	{
		return view("myview",['name'=>"zhangsan","info"=>"<b>BBBBBB</b><i>IIIIIIII</i>"]);
	}
}